DR1='N:'
F1='DLV_PHAR'
F11='DLVPO'
F12='DLVDO'
SELE 1
SET EXCLU OFF
USE &DR&F1
*INDEX ON PO_NUMB_CL TO &DR&F11
*INDEX ON delv_order TO &DR&F12
SET EXCLU OFF
CLOSE DATA
CLOSE INDEX
F1='COMPANY'
F2='DLV_PHAR'
F3='DLV_TEMP'
PL2=1
DO WHILE .T.
   set colo to bg+/b,w+/n
*   @  8,1 CLEA TO 18,78
*   @  8, 5 SAY "CLIENT CODE :"
*   @  7, 3 TO 9, 24 DOUBLE
   COMPCOD = SPACE(4)
   F1='COMPANY'
   f11='nmcomp'
   set colo to bg+/b,w+/n
   @ 7,1 clear to 23,78
   CNT=0
   KODE=SPACE(4)
   kunci=space(5)
   do boxe with 11,3,'Enter Initial of Client Name : ','KUNCI','N','BG','W+','N',5,.T.,.T.
   if lastkey()=27
      set colo to bg+/b,w+/n
      return
   endif

   do getcomp
   if lastkey()=27
      return
   endif
   set colo to bg+/b,w+/n
   sele 1
   SET EXCLU OFF
   USE &DR&F1 INDEX &DR&F1
*   @  8, 19  GET COMPCOD
*   READ
*   IF COMPCOD=SPAC(4)
*      CLOSE DATA
*      CLOSE INDEX
*      RETURN
*   ENDIF
   SEEK COMPCOD
   IF EOF()
      @ 12, 48  SAY "THIS CODE DOES NOT CORRESPOND"
      @ 13, 48  SAY ">>>> TO A LISTED COMPANY <<<<"
      @ 14, 48  SAY ">>>> PLEASE ENTER AGAIN !<<<<"
      STORE 0 TO MX
      DO WHILE MX=0
         MX=INKEY()
      ENDDO
      DO CASE
         CASE MX=13
            LOOP
      ENDCASE
      LOOP
   ENDIF
   set colo to bg+/b,w+/n
*   @ 20,  5 CLEAR TO 22, 74
   @ 7,  1 CLEAR TO 23, 78
   COMPNAME = COMP_NAME
   COMPADD1 = COMP_ADD1
   COMPTEL1 = COMP_TEL1
   COMPFAX = COMP_FAX
   COMPTELEX = COMP_TELEX
   @ 20, 5  CLEAR TO 20, 74
   @ 21, 5  CLEAR TO 21, 74
   @ 22, 5  CLEAR TO 22, 74
   @ 20, 5  SAY "CLIENT  :"
   @ 21, 5  SAY "ADDRESS :"
   @ 22, 5  SAY "TEL :                  FAX :                 TELEX :"
   @ 20,15  SAY COMPNAME
   @ 21,15  SAY COMPADD1
   @ 22,11  SAY COMPTEL1
   @ 22,34  SAY COMPFAX
   @ 22,58  SAY COMPTELEX
   @ 16,3  TO 18,32 DOUBLE
   @ 17,5  SAY 'IS IT A NEW P.O. (Y/N) :'
   POYN=' '
   @ 17,30  GET POYN PICT '@!' VALID POYN $ 'YN'
   READ
   DO WHILE .T.
      IF POYN='Y'
         @ 16,3  CLEA TO 18,32
         @ 16,3  TO 18,35 DOUBLE
         @ 17,5  SAY 'P.O. # :'
         NUMPO=SPAC(20)
         DO WHILE NUMPO=SPAC(20)
            @ 17,14 GET NUMPO PICT '@!'
            READ
            IF LASTKEY()=27
               CLOSE DATA
               CLOSE INDEX
               RETURN
            ENDIF
            SELE 2
            SET EXCLU OFF
            USE &DR&F2 INDEX &DR&F11
            SEEK NUMPO
            IF .NOT. EOF()
               POYN='N'
               EXIT
            ENDIF
         ENDDO
      ENDIF
      IF POYN='N'
         @ 16,3  CLEA TO 18,32
         F2='DLV_PHAR'
         F3='DLV_TEMP'
         F11='DLVPO'
         SELE 2
         SET EXCLU OFF
         USE &DR&F2 INDEX &DR&F11
         SELE 3
         USE
         IF NET_USE("&DR&F3",.T.,'3',10)
            ZAP
         ENDIF
         SET EXCLU OFF
         SELE 2
         GO TOP
         DO WHILE .NOT. EOF()
            IF COMP_CODE<>COMPCOD
               SKIP
               LOOP
            ENDIF
            IF PO_NUMB_CL=SPAC(20)
               SKIP
               LOOP
            ENDIF
            NOPO=PO_NUMB_CL
            ct=0
            DO WHILE PO_NUMB_CL=NOPO .AND. .NOT. EOF()
               if ct=0
                 SELE 3
                 IF FIL_LOCK(0)
                    APPEND BLANK
                 ENDIF
                 IF REC_LOCK(0)
                    REPL PO_NUMB_CL WITH NOPO
                 ENDIF
                 UNLOCK
                 ct=1
               endif
               sele 2
               SKIP
            ENDDO

         ENDDO
         SELE 3
         SET EXCLU OFF
         COUNT TO CNT
         DECLARE FILD[CNT]
         IF CNT=0
            POYN='Y'
            LOOP
         ENDIF
         GOTO TOP
         CR=0
         DO WHILE .NOT. EOF()
            CR=CR+1
            FILD[CR]=PO_NUMB_CL
            SKIP
         ENDDO
         @ 10,  3  TO 18, 31    DOUBLE
         @ 11, 5 SAY 'P.O. #'
         @ 12, 4 TO 12,30
         inkey()
         cari=achoice(13,5,17,24,fild)
         mix=lastkey()
         DO CASE
            CASE MIX=13
               NUMPO=FILD[CARI]
               EXIT
            CASE MIX=27
               POYN='Y'
               LOOP
         ENDCASE
      ENDIF
      EXIT
   ENDDO
   @ 16,32  TO 18,67 DOUBLE
   @ 17,33 CLEA TO 17,66
*   @ 18,33 clea to 18,66
*   @ 19,33 clea to 19,66
*   @ 20,33 clea to 20,66
*   @ 21,33 clea to 21,66
*   @ 22,33 clea to 22,66
   @ 17,34  SAY 'P.O. # : '
   @ 17,43 SAY NUMPO
   @ 10,  3  TO 18, 31    DOUBLE
   @ 11,  4  clea to 17,30
   @ 11,  5  PROMPT "A. PREPARE DELIVERY ORDER "
   @ 17,  5  PROMPT "X. BACK TO PREVIOUS MENU  "
   MENU TO PL2
   SET COLO TO BG+/B,W+/N
   IF LAST()=27
      RETURN
   ENDIF
   TOTL=0
   REST FROM N:DELNUM ADDI
   VALDEN=VAL(DELNU)+1
   DO CASE
      CASE VALDEN<10
         DELNU='000'+STR(VAL(DELNU)+1,1,0)
      CASE VALDEN<100
         DELNU='00'+STR(VAL(DELNU)+1,2,0)
      CASE VALDEN<1000
         DELNU='0'+STR(VAL(DELNU)+1,3,0)
      OTHERWISE
         DELNU=STR(VAL(DELNU)+1,4,0)
   ENDCASE
   SAVE ALL LIKE DELNU TO N:DELNUM
   COUNINP=0
   DO CASE
      CASE PL2=1
         DO DO_1A
         IF COUNINP=0
            DO CASE
               CASE VAL(DELNU)<=10
                  DELNU='000'+STR(VAL(DELNU)-1,1,0)
               CASE VAL(DELNU)<=100
                  DELNU='00'+STR(VAL(DELNU)-1,2,0)
               CASE VAL(DELNU)<=1000
                 DELNU='0'+STR(VAL(DELNU)-1,3,0)
               OTHERWISE
                 DELNU=STR(VAL(DELNU)-1,4,0)
            ENDCASE
            SAVE ALL LIKE DELNU TO N:DELNUM
         ENDIF

      CASE PL2=2
         DO CASE
            CASE VAL(DELNU)<=10
               DELNU='000'+STR(VAL(DELNU)-1,1,0)
            CASE VAL(DELNU)<=100
               DELNU='00'+STR(VAL(DELNU)-1,2,0)
            CASE VAL(DELNU)<=1000
               DELNU='0'+STR(VAL(DELNU)-1,3,0)
            OTHERWISE
               DELNU=STR(VAL(DELNU)-1,4,0)
         ENDCASE
         SAVE ALL LIKE DELNU TO N:DELNUM
         SET EXCLU OFF
         CLOSE DATA
         CLOSE INDEX
         RETURN
   ENDCASE
ENDDO
